<template>
  <router-view />
</template>

<script setup>
import router from "@/router";
import { useTableStore } from "@/store/table";
import { useFormStore } from "@/store/form";
const websocket = new WebSocket("ws://localhost:4001");

const tableStore = useTableStore();
const formStore = useFormStore();

//接收到消息的回调方法
websocket.onmessage = function (event) {
  const data = JSON.parse(event.data);
  console.log("websocket.onmessage", data);
  if (data?.type === "table") {
    tableStore.handleAxureData(data);
    router.push("/table");
  } else if (data?.type === "form") {
    formStore.handleAxureData(data);
    router.push("/form");
  }
};
</script>
